//
//  ViewController.m
//  TomCat
//
//  Created by mac on 01-9-1.
//  Copyright (c) 2001年 hyd. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)drink;
- (IBAction)knockout;
- (IBAction)foot_left;
- (IBAction)eat;
- (IBAction)cymbal;
- (IBAction)pie;
- (IBAction)fart;
- (IBAction)scratch;
- (IBAction)foot_right;
- (IBAction)stomach;
- (IBAction)angry;


@property (weak, nonatomic) IBOutlet UIImageView *ImageViewCat;

@end

@implementation ViewController
- (void)startAnimating:(int)count picName:(NSString*)picName
{
    
    //判断当前动画是否正在执行，如果正在执行该次点击无效
    if (self.ImageViewCat.isAnimating == 1) {
        return;
   }
    NSMutableArray * arrayM = [NSMutableArray array];
    for (int i = 0; i<count; i++) {
        NSString * imaName = [NSString
        stringWithFormat:@"%@_%02d.jpg",picName,i];
        //根据图片名字得到图片
        //UIImage * imgCat = [UIImage imageNamed:imaName];
        NSString * path = [[NSBundle mainBundle]pathForResource:imaName ofType:nil];
        UIImage * imgCat = [UIImage imageWithContentsOfFile:path];
        //将每次获取的图片放到数组中去
        [arrayM addObject:imgCat];
    }
    //2.将得到的帧动画的数组赋给 uiimageview的帧动画数组属性
    self.ImageViewCat.animationImages = arrayM;
    
    //3.设置动画播放时间
    self.ImageViewCat.animationDuration = self.
    ImageViewCat.animationImages.count * 0.1;
    //4.设置动画循环次数
    self.ImageViewCat.animationRepeatCount = 1;
    
    //5.开始播放帧动画
    [self.ImageViewCat startAnimating];
    
    //6.动画播放完之后清空缓存
    //self.ImageViewCat.animationImages = nil;
    [self.ImageViewCat performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.
     ImageViewCat.animationImages.count * 0.1];
    

}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)drink {
    
    /*NSMutableArray * arrayM = [NSMutableArray array];
    for (int i = 0; i<80; i++) {
        NSString * imaName = [NSString
        stringWithFormat:@"drink_%02d.jpg",i];
        //根据图片名字得到图片
        UIImage * imgCat = [UIImage imageNamed:imaName];
        //将每次获取的图片放到数组中去
        [arrayM addObject:imgCat];
    }
    //2.将得到的帧动画的数组赋给 uiimageview的帧动画数组属性
    self.ImageViewCat.animationImages = arrayM;
    
    //3.设置动画播放时间
    self.ImageViewCat.animationDuration = self.
    ImageViewCat.animationImages.count * 0.1;
    //4.设置动画循环次数
    self.ImageViewCat.animationRepeatCount = 1;
    
    //5.开始播放帧动画
    [self.ImageViewCat startAnimating];
    */

    [self startAnimating:80 picName:@"drink"];
    
}

- (IBAction)knockout {
    
    [self startAnimating:80 picName:@"knockout"];

    
}

- (IBAction)foot_left {
    
    [self startAnimating:29 picName:@"foot_left"];

    
}

- (IBAction)eat {
    
    [self startAnimating:39 picName:@"eat"];

    
}

- (IBAction)cymbal {
    [self startAnimating:12 picName:@"cymbal"];

    
}

- (IBAction)pie {
    [self startAnimating:23 picName:@"pie"];

}

- (IBAction)fart {
    
    [self startAnimating:27 picName:@"fart"];

}

- (IBAction)scratch {
    [self startAnimating:55 picName:@"scratch"];

}

- (IBAction)foot_right {
    
    [self startAnimating:29 picName:@"foot_right"];

}

- (IBAction)stomach {
    
    
    [self startAnimating:33 picName:@"stomach"];

}

- (IBAction)angry {
    
    [self startAnimating:25 picName:@"angry"];

}


@end
